﻿using System;
using System.Windows.Forms;
using System.Drawing;

namespace HorrorsOfArkham.Game_Application_Layer
{
    public partial class GameForm : Form, IRenderView
    {
        private XnaControl xnaControl;
        private MyXnaGame _game;

        public Size ViewSize
        {
            get 
            {
                return xnaControl.ClientSize;
            }
        }

        #region Initialization

        public GameForm()
        {
            InitializeComponent();
        }

        #endregion

        #region Rendering

        public void Render()
        {
            _game.Tick();
        }

        #endregion

        #region Other Methods

        protected override void OnShown(EventArgs e)
        {
            _game = new MyXnaGame(xnaControl.GraphicsDevice, new DirectoryContentManagerProvider(), this);
            _game.Run();

            base.OnShown(e);
        }

        protected override void OnFormClosed(FormClosedEventArgs e)
        {
            if (_game != null)
            {
                _game.Dispose();
            }
            
            base.OnFormClosed(e);
        }

        #endregion

        private void InitializeComponent()
        {
            this.xnaControl = new HorrorsOfArkham.Game_Application_Layer.XnaControl();
            this.SuspendLayout();
            // 
            // xnaControl
            // 
            this.xnaControl.Dock = System.Windows.Forms.DockStyle.Fill;
            this.xnaControl.Location = new System.Drawing.Point(0, 0);
            this.xnaControl.Name = "xnaControl";
            this.xnaControl.Size = new System.Drawing.Size(784, 562);
            this.xnaControl.TabIndex = 0;
            this.xnaControl.TabStop = false;
            this.xnaControl.Text = "xnaControl";
            // 
            // GameForm
            // 
            this.ClientSize = new System.Drawing.Size(784, 562);
            this.Controls.Add(this.xnaControl);
            this.Name = "GameForm";
            this.ResumeLayout(false);

        }
    }
}
